package samples.barcode;

import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import br.cin.ufpe.in1118.middleware.distribution.services.naming.Naming;
import br.cin.ufpe.in1118.middleware.distribution.services.naming.NamingService;
import br.cin.ufpe.in1118.middleware.exceptions.RemoteException;

public class BarcodeClient {

	public static void main(String[] args) {
		Barcode barcoder = null;
		Naming naming = NamingService.getNamingInstance("localhost", 9001);
		try {
			Object obj = naming.lookup(Barcode.SERVICE_NAME);
			if (obj instanceof Barcode) {
				barcoder = (Barcode) obj;
			}
			
			final ImageIcon icon = barcoder.createBarCode(489340);
			
			JFrame jf = new JFrame();
			JPanel jp = new JPanel();
			JLabel label = new JLabel();
			label.setIcon(icon);
			jp.add(label);
			jp.setPreferredSize(new Dimension(82,50));
			jf.setContentPane(jp);
			jf.setResizable(false);
			jf.setLocationRelativeTo(null);
			jf.pack();
			jf.setVisible(true);
			jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
			
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
